

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="一： 软件工具1.1 Python3这里选择的是最新版 Python3安装教程这里推荐：http://www.runoob.com/python3/python3-install.htmlwin下载地址：https://www.python.org/downloads/windowsLinux下载地址：https://www.python.org/downloads/source">
  <meta name="author" content="closer">
  <meta name="keywords" content="">
  
  <title>python爬图攻略 - closer的自留地</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10.6.0/styles/androidstudio.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"blog.zsaa.top","root":"/","version":"1.8.10","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"always","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"baidu":"608f2baddd361128381ad2bf9377bf89","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"YzLqNtMw1YEwwACli1FUsIUM-gzGzoHsz","app_key":"HLUt5izfTvTcbEbOrA59W92a","server_url":"https://yzlqntmw.lc-cn-n1-shared.com"}}};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>Hello</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="python爬图攻略">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-02-16 10:54" pubdate>
        2020年2月16日 上午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.2k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      35
       分钟
    </span>
  

  
  
    
      <!-- LeanCloud 统计文章PV -->
      <span id="leancloud-page-views-container" class="post-meta" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="leancloud-page-views"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">python爬图攻略</h1>
            
              <p class="note note-info">
                
                  本文最后更新于：2020年2月23日 下午
                
              </p>
            
            <div class="markdown-body">
              <h2 id="一：-软件工具"><a href="#一：-软件工具" class="headerlink" title="一： 软件工具"></a>一： 软件工具</h2><h3 id="1-1-Python3"><a href="#1-1-Python3" class="headerlink" title="1.1 Python3"></a>1.1 Python3</h3><p>这里选择的是最新版 Python3<br>安装教程这里推荐：<a target="_blank" rel="noopener" href="http://www.runoob.com/python3/python3-install.html">http://www.runoob.com/python3/python3-install.html</a><br>win下载地址：<a target="_blank" rel="noopener" href="https://www.python.org/downloads/windows">https://www.python.org/downloads/windows</a><br>Linux下载地址：<a target="_blank" rel="noopener" href="https://www.python.org/downloads/source">https://www.python.org/downloads/source</a>  <span id="more"></span></p>
<h3 id="1-2-PyCharm"><a href="#1-2-PyCharm" class="headerlink" title="1.2 PyCharm"></a>1.2 PyCharm</h3><p>可视化开发工具IDE：<a target="_blank" rel="noopener" href="https://www.jetbrains.com/pycharm/download/">https://www.jetbrains.com/pycharm/download/</a></p>
<h2 id="二：原理"><a href="#二：原理" class="headerlink" title="二：原理"></a>二：原理</h2><h3 id="2-1-实现步骤"><a href="#2-1-实现步骤" class="headerlink" title="2.1 实现步骤"></a>2.1 实现步骤</h3><p>以图片为例，其实很简单，分以下四步：</p>
<ul>
<li>获取首页的页码数，并创建与页码对应的文件夹</li>
<li>获取页面的栏目地址</li>
<li>进入栏目，获取栏目页码数(每个栏目下有多张图片，分页显示)</li>
<li>获取到栏目下对用标签容器中的图片并下载</li>
</ul>
<h3 id="2-2-注意事项"><a href="#2-2-注意事项" class="headerlink" title="2.2 注意事项"></a>2.2 注意事项</h3><p>这里以爬取某个网站的套路为例，详细见代码，这里主要说以下几点注意事项：  </p>
<p>1）导库，其实就类似于Java中框架或者是工具类，底层都被封装好了</p>
<p>安装第三方库：</p>
<figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py"><span class="hljs-comment"># Win下直接装的 python3</span><br>pip install BeautifulSoup4 -i https://pypi.tuna.tsinghua.edu.cn/simple<br>pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple<br><span class="hljs-comment"># Linux python2 python3 共存</span><br>pip3 install BeautifulSoup4 -i https://pypi.tuna.tsinghua.edu.cn/simple<br>pip3 install requests -i https://pypi.tuna.tsinghua.edu.cn/simple<br></code></pre></div></td></tr></table></figure>

<p>导入第三方库：</p>
<figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py"><span class="hljs-comment"># 导入requests库</span><br><span class="hljs-keyword">import</span> requests<br><span class="hljs-comment"># 导入文件操作库</span><br><span class="hljs-keyword">import</span> os<br><span class="hljs-comment"># bs4全名BeautifulSoup4，是编写python爬虫常用库之一，主要用来解析html标签。</span><br><span class="hljs-keyword">import</span> bs4<br><span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup<br><span class="hljs-comment"># 基础类库</span><br><span class="hljs-keyword">import</span> sys<br><span class="hljs-comment"># Python 3.x 解决中文编码问题</span><br><span class="hljs-keyword">import</span> importlib<br>importlib.reload(sys)<br></code></pre></div></td></tr></table></figure>

<p>2）定义方法函数，一个爬虫可能会几百行，所以尽量不要写成一坨</p>
<figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">download</span>(<span class="hljs-params">page_no, file_path</span>):</span><br>    <span class="hljs-comment"># 这里写代码逻辑</span><br></code></pre></div></td></tr></table></figure>

<p>3）定义全局变量</p>
<figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py"><span class="hljs-comment"># 给请求指定一个请求头来模拟chrome浏览器</span><br><span class="hljs-keyword">global</span> headers <span class="hljs-comment"># 告诉编译器这是全局变量 headers </span><br>headers = &#123;<span class="hljs-string">&#x27;User-Agent&#x27;</span>: <span class="hljs-string">&#x27;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36&#x27;</span>&#125;<br><br><span class="hljs-comment"># 函数内使用之前需要</span><br><span class="hljs-comment"># 告诉编译器我在这个方法中使用的a是刚才定义的全局变量 headers ，而不是方法内部的局部变量。</span><br><span class="hljs-keyword">global</span> headers<br></code></pre></div></td></tr></table></figure>

<p>4）防盗链</p>
<p>有些网站加入了防盗链，无所不能的 python  解决方案：</p>
<figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py">headers = &#123;<span class="hljs-string">&#x27;Referer&#x27;</span>: href&#125;<br>img = requests.get(url, headers=headers)<br></code></pre></div></td></tr></table></figure>

<p>5）切换版本</p>
<p>Linux服务器使用的是阿里云服务器（centos7.4），默认版本 python2，python3 自行安装</p>
<figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py">[root@AY140216131049Z mzitu]<span class="hljs-comment"># python2 -V</span><br>Python <span class="hljs-number">2.7</span><span class="hljs-number">.5</span><br>[root@AY140216131049Z mzitu]<span class="hljs-comment"># python3 -V</span><br>Python <span class="hljs-number">3.7</span><span class="hljs-number">.1</span><br><span class="hljs-comment"># 默认版本</span><br>[root@AY140216131049Z mzitu]<span class="hljs-comment"># python -V</span><br>Python <span class="hljs-number">2.7</span><span class="hljs-number">.5</span><br><span class="hljs-comment"># 临时切换版本 &lt;whereis python&gt;</span><br>[root@AY140216131049Z mzitu]<span class="hljs-comment"># alias python=&#x27;/usr/local/bin/python3.7&#x27;</span><br>[root@AY140216131049Z mzitu]<span class="hljs-comment"># python -V</span><br>Python <span class="hljs-number">3.7</span><span class="hljs-number">.1</span><br><br></code></pre></div></td></tr></table></figure>

<p>6）异常捕获</p>
<p>在爬取的过程中可能存在异常页面，这里我们进行捕获，不影响后续操作：</p>
<figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py"><span class="hljs-keyword">try</span>:<br>    <span class="hljs-comment"># 业务逻辑</span><br><span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:<br>   <span class="hljs-built_in">print</span>(e)<br></code></pre></div></td></tr></table></figure>

<h3 id="2-3-执行脚本"><a href="#2-3-执行脚本" class="headerlink" title="2.3 执行脚本"></a>2.3 执行脚本</h3><figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py">python3 mzitu.py<br><br><span class="hljs-comment"># 或者后台执行</span><br><br>nohup python3 -u mzitu.py &gt; mzitu.log <span class="hljs-number">2</span>&gt;&amp;<span class="hljs-number">1</span> &amp;<br></code></pre></div></td></tr></table></figure>

<h2 id="三：-源码"><a href="#三：-源码" class="headerlink" title="三： 源码"></a>三： 源码</h2><h3 id="3-1-win下代码"><a href="#3-1-win下代码" class="headerlink" title="3.1 win下代码"></a>3.1 win下代码</h3><figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py"><span class="hljs-comment">#coding=utf-8</span><br><span class="hljs-comment">#!/usr/bin/python</span><br><span class="hljs-comment"># 导入requests库</span><br><span class="hljs-keyword">import</span> requests<br><span class="hljs-comment"># 导入文件操作库</span><br><span class="hljs-keyword">import</span> os<br><span class="hljs-keyword">import</span> bs4<br><span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup<br><span class="hljs-keyword">import</span> sys<br><span class="hljs-keyword">import</span> importlib<br><span class="hljs-keyword">import</span> random<br><span class="hljs-keyword">import</span> time<br>importlib.reload(sys)<br><br><br><span class="hljs-comment"># 越多越好</span><br>meizi_headers = [<br>    <span class="hljs-string">&quot;Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36&quot;</span>,<br>    <span class="hljs-string">&quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36&quot;</span>,<br>    <span class="hljs-string">&quot;Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0&quot;</span>,<br>    <span class="hljs-string">&quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14&quot;</span>,<br>    <span class="hljs-string">&quot;Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)&quot;</span>,<br>    <span class="hljs-string">&#x27;Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11&#x27;</span>,<br>    <span class="hljs-string">&#x27;Opera/9.25 (Windows NT 5.1; U; en)&#x27;</span>,<br>    <span class="hljs-string">&#x27;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)&#x27;</span>,<br>    <span class="hljs-string">&#x27;Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Kubuntu)&#x27;</span>,<br>    <span class="hljs-string">&#x27;Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-security Firefox/1.5.0.12&#x27;</span>,<br>    <span class="hljs-string">&#x27;Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.2.9&#x27;</span>,<br>    <span class="hljs-string">&quot;Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Ubuntu/11.04 Chromium/16.0.912.77 Chrome/16.0.912.77 Safari/535.7&quot;</span>,<br>    <span class="hljs-string">&quot;Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0&quot;</span>,<br>    <span class="hljs-string">&#x27;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36&#x27;</span><br>]<br><span class="hljs-comment"># 给请求指定一个请求头来模拟chrome浏览器</span><br><span class="hljs-keyword">global</span> headers<br>headers = &#123;<span class="hljs-string">&#x27;User-Agent&#x27;</span>: random.choice(meizi_headers)&#125;<br><span class="hljs-comment"># 爬图网址</span><br>mziTu = <span class="hljs-string">&#x27;http://www.mzitu.com/&#x27;</span><br><span class="hljs-comment"># 定义图片存储位置</span><br><span class="hljs-keyword">global</span> save_path<br>save_path = <span class="hljs-string">&#x27;D:\BeautifulPictures&#x27;</span><br><br><span class="hljs-comment"># 创建文件夹</span><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">createFile</span>(<span class="hljs-params">file_path</span>):</span><br>    <span class="hljs-keyword">if</span> os.path.exists(file_path) <span class="hljs-keyword">is</span> <span class="hljs-literal">False</span>:<br>        os.makedirs(file_path)<br>    <span class="hljs-comment"># 切换路径至上面创建的文件夹</span><br>    os.chdir(file_path)<br><br><span class="hljs-comment"># 下载文件</span><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">download</span>(<span class="hljs-params">page_no, file_path</span>):</span><br>    <span class="hljs-keyword">global</span> headers<br>    res_sub = requests.get(page_no, headers=headers)<br>    <span class="hljs-comment"># 解析html</span><br>    soup_sub = BeautifulSoup(res_sub.text, <span class="hljs-string">&#x27;html.parser&#x27;</span>)<br>    <span class="hljs-comment"># 获取页面的栏目地址</span><br>    all_a = soup_sub.find(<span class="hljs-string">&#x27;div&#x27;</span>,class_=<span class="hljs-string">&#x27;postlist&#x27;</span>).find_all(<span class="hljs-string">&#x27;a&#x27;</span>,target=<span class="hljs-string">&#x27;_blank&#x27;</span>)<br>    count = <span class="hljs-number">0</span><br>    <span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> all_a:<br>        count = count + <span class="hljs-number">1</span><br>        <span class="hljs-keyword">if</span> (count % <span class="hljs-number">2</span>) == <span class="hljs-number">0</span>:<br>            headers = &#123;<span class="hljs-string">&#x27;User-Agent&#x27;</span>: random.choice(meizi_headers)&#125;<br>            <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;内页第几页：&quot;</span> + <span class="hljs-built_in">str</span>(count))<br>            <span class="hljs-comment"># 提取href</span><br>            href = a.attrs[<span class="hljs-string">&#x27;href&#x27;</span>]<br>            <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;套图地址：&quot;</span> + href)<br>            res_sub_1 = requests.get(href, headers=headers)<br>            soup_sub_1 = BeautifulSoup(res_sub_1.text, <span class="hljs-string">&#x27;html.parser&#x27;</span>)<br>            <span class="hljs-comment"># ------ 这里最好使用异常处理 ------</span><br>            <span class="hljs-keyword">try</span>:<br>                <span class="hljs-comment"># 获取套图的最大数量</span><br>                pic_max = soup_sub_1.find(<span class="hljs-string">&#x27;div&#x27;</span>, class_=<span class="hljs-string">&#x27;pagenavi&#x27;</span>).find_all(<span class="hljs-string">&#x27;span&#x27;</span>)[<span class="hljs-number">6</span>].text<br>                <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;套图数量：&quot;</span> + pic_max)<br>                <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-built_in">int</span>(pic_max) + <span class="hljs-number">1</span>):<br>                    <span class="hljs-comment"># 单位为秒，1-3 随机数</span><br>                    time.sleep(random.randint(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>))<br>                    headers = &#123;<span class="hljs-string">&#x27;User-Agent&#x27;</span>: random.choice(meizi_headers)&#125;<br>                    <span class="hljs-comment"># print(&quot;子内页第几页：&quot; + str(j))</span><br>                    <span class="hljs-comment"># j int类型需要转字符串</span><br>                    href_sub = href + <span class="hljs-string">&quot;/&quot;</span> + <span class="hljs-built_in">str</span>(j)<br>                    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;图片地址：&quot;</span>+href_sub)<br>                    res_sub_2 = requests.get(href_sub, headers=headers)<br>                    soup_sub_2 = BeautifulSoup(res_sub_2.text, <span class="hljs-string">&quot;html.parser&quot;</span>)<br>                    img = soup_sub_2.find(<span class="hljs-string">&#x27;div&#x27;</span>, class_=<span class="hljs-string">&#x27;main-image&#x27;</span>).find(<span class="hljs-string">&#x27;img&#x27;</span>)<br>                    <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(img, bs4.element.Tag):<br>                        <span class="hljs-comment"># 提取src</span><br>                        url = img.attrs[<span class="hljs-string">&#x27;src&#x27;</span>]<br>                        array = url.split(<span class="hljs-string">&#x27;/&#x27;</span>)<br>                        file_name = array[<span class="hljs-built_in">len</span>(array)-<span class="hljs-number">1</span>]<br>                        <span class="hljs-comment"># 防盗链加入Referer</span><br>                        headers = &#123;<span class="hljs-string">&#x27;User-Agent&#x27;</span>: random.choice(meizi_headers), <span class="hljs-string">&#x27;Referer&#x27;</span>: url&#125;<br>                        img = requests.get(url, headers=headers)<br>                        <span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;开始保存图片&#x27;</span>, img)<br>                        f = <span class="hljs-built_in">open</span>(file_name, <span class="hljs-string">&#x27;ab&#x27;</span>)<br>                        f.write(img.content)<br>                        <span class="hljs-built_in">print</span>(file_name, <span class="hljs-string">&#x27;图片保存成功！&#x27;</span>)<br>                        f.close()<br>            <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:<br>                <span class="hljs-built_in">print</span>(e)<br><br><br><span class="hljs-comment"># 主方法</span><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span>():</span><br>    res = requests.get(mziTu, headers=headers)<br>    <span class="hljs-comment"># 使用自带的html.parser解析</span><br>    soup = BeautifulSoup(res.text, <span class="hljs-string">&#x27;html.parser&#x27;</span>)<br>    <span class="hljs-comment"># 创建文件夹</span><br>    createFile(save_path)<br>    <span class="hljs-comment"># 获取首页总页数</span><br>    img_max = soup.find(<span class="hljs-string">&#x27;div&#x27;</span>, class_=<span class="hljs-string">&#x27;nav-links&#x27;</span>).find_all(<span class="hljs-string">&#x27;a&#x27;</span>)[<span class="hljs-number">3</span>].text<br>    <span class="hljs-comment"># print(&quot;总页数:&quot;+img_max)</span><br>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-built_in">int</span>(img_max) + <span class="hljs-number">1</span>):<br>        <span class="hljs-comment"># 获取每页的URL地址</span><br>        <span class="hljs-keyword">if</span> i == <span class="hljs-number">1</span>:<br>            page = mziTu<br>        <span class="hljs-keyword">else</span>:<br>            page = mziTu + <span class="hljs-string">&#x27;page/&#x27;</span> + <span class="hljs-built_in">str</span>(i)<br>        file = save_path + <span class="hljs-string">&#x27;\\&#x27;</span> + <span class="hljs-built_in">str</span>(i)<br>        createFile(file)<br>        <span class="hljs-comment"># 下载每页的图片</span><br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;套图页码：&quot;</span> + page)<br>        download(page, file)<br><br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    main()<br></code></pre></div></td></tr></table></figure>

<h3 id="3-2-linux下代码"><a href="#3-2-linux下代码" class="headerlink" title="3.2 linux下代码"></a>3.2 linux下代码</h3><figure class="highlight py"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs py"><span class="hljs-comment">#coding=utf-8</span><br><span class="hljs-comment">#!/usr/bin/python</span><br><span class="hljs-comment"># 导入requests库</span><br><span class="hljs-keyword">import</span> requests<br><span class="hljs-comment"># 导入文件操作库</span><br><span class="hljs-keyword">import</span> os<br><span class="hljs-keyword">import</span> bs4<br><span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup<br><span class="hljs-keyword">import</span> sys<br><span class="hljs-keyword">import</span> importlib<br>importlib.reload(sys)<br><br><span class="hljs-comment"># 给请求指定一个请求头来模拟chrome浏览器</span><br><span class="hljs-keyword">global</span> headers<br>headers = &#123;<span class="hljs-string">&#x27;User-Agent&#x27;</span>: <span class="hljs-string">&#x27;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36&#x27;</span>&#125;<br><span class="hljs-comment"># 爬图地址</span><br>mziTu = <span class="hljs-string">&#x27;http://www.mzitu.com/&#x27;</span><br><span class="hljs-comment"># 定义存储位置</span><br><span class="hljs-keyword">global</span> save_path<br>save_path = ​<span class="hljs-string">&#x27;/mnt/data/mzitu&#x27;</span><br><br><span class="hljs-comment"># 创建文件夹</span><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">createFile</span>(<span class="hljs-params">file_path</span>):</span><br>    <span class="hljs-keyword">if</span> os.path.exists(file_path) <span class="hljs-keyword">is</span> <span class="hljs-literal">False</span>:<br>        os.makedirs(file_path)<br>    <span class="hljs-comment"># 切换路径至上面创建的文件夹</span><br>    os.chdir(file_path)<br><br><span class="hljs-comment"># 下载文件</span><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">download</span>(<span class="hljs-params">page_no, file_path</span>):</span><br>    <span class="hljs-keyword">global</span> headers<br>    res_sub = requests.get(page_no, headers=headers)<br>    <span class="hljs-comment"># 解析html</span><br>    soup_sub = BeautifulSoup(res_sub.text, <span class="hljs-string">&#x27;html.parser&#x27;</span>)<br>    <span class="hljs-comment"># 获取页面的栏目地址</span><br>    all_a = soup_sub.find(<span class="hljs-string">&#x27;div&#x27;</span>,class_=<span class="hljs-string">&#x27;postlist&#x27;</span>).find_all(<span class="hljs-string">&#x27;a&#x27;</span>,target=<span class="hljs-string">&#x27;_blank&#x27;</span>)<br>    count = <span class="hljs-number">0</span><br>    <span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> all_a:<br>        count = count + <span class="hljs-number">1</span><br>        <span class="hljs-keyword">if</span> (count % <span class="hljs-number">2</span>) == <span class="hljs-number">0</span>:<br>            <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;内页第几页：&quot;</span> + <span class="hljs-built_in">str</span>(count))<br>            <span class="hljs-comment"># 提取href</span><br>            href = a.attrs[<span class="hljs-string">&#x27;href&#x27;</span>]<br>            <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;套图地址：&quot;</span> + href)<br>            res_sub_1 = requests.get(href, headers=headers)<br>            soup_sub_1 = BeautifulSoup(res_sub_1.text, <span class="hljs-string">&#x27;html.parser&#x27;</span>)<br>            <span class="hljs-comment"># ------ 这里最好使用异常处理 ------</span><br>            <span class="hljs-keyword">try</span>:<br>                <span class="hljs-comment"># 获取套图的最大数量</span><br>                pic_max = soup_sub_1.find(<span class="hljs-string">&#x27;div&#x27;</span>,class_=<span class="hljs-string">&#x27;pagenavi&#x27;</span>).find_all(<span class="hljs-string">&#x27;span&#x27;</span>)[<span class="hljs-number">6</span>].text<br>                <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;套图数量：&quot;</span> + pic_max)<br>                <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-built_in">int</span>(pic_max) + <span class="hljs-number">1</span>):<br>                    <span class="hljs-comment"># print(&quot;子内页第几页：&quot; + str(j))</span><br>                    <span class="hljs-comment"># j int类型需要转字符串</span><br>                    href_sub = href + <span class="hljs-string">&quot;/&quot;</span> + <span class="hljs-built_in">str</span>(j)<br>                    <span class="hljs-built_in">print</span>(href_sub)<br>                    res_sub_2 = requests.get(href_sub, headers=headers)<br>                    soup_sub_2 = BeautifulSoup(res_sub_2.text, <span class="hljs-string">&quot;html.parser&quot;</span>)<br>                    img = soup_sub_2.find(<span class="hljs-string">&#x27;div&#x27;</span>, class_=<span class="hljs-string">&#x27;main-image&#x27;</span>).find(<span class="hljs-string">&#x27;img&#x27;</span>)<br>                    <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(img, bs4.element.Tag):<br>                        <span class="hljs-comment"># 提取src</span><br>                        url = img.attrs[<span class="hljs-string">&#x27;src&#x27;</span>]<br>                        array = url.split(<span class="hljs-string">&#x27;/&#x27;</span>)<br>                        file_name = array[<span class="hljs-built_in">len</span>(array)-<span class="hljs-number">1</span>]<br>                        <span class="hljs-comment"># print(file_name)</span><br>                        <span class="hljs-comment"># 防盗链加入Referer</span><br>                        headers = &#123;<span class="hljs-string">&#x27;Referer&#x27;</span>: href&#125;<br>                        img = requests.get(url, headers=headers)<br>                        <span class="hljs-comment"># print(&#x27;开始保存图片&#x27;)</span><br>                        f = <span class="hljs-built_in">open</span>(file_name, <span class="hljs-string">&#x27;ab&#x27;</span>)<br>                        f.write(img.content)<br>                        <span class="hljs-comment"># print(file_name, &#x27;图片保存成功！&#x27;)</span><br>                        f.close()<br>            <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:<br>                <span class="hljs-built_in">print</span>(e)<br><br><br><span class="hljs-comment"># 主方法</span><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span>():</span><br>    res = requests.get(mziTu, headers=headers)<br>    <span class="hljs-comment"># 使用自带的html.parser解析</span><br>    soup = BeautifulSoup(res.text, <span class="hljs-string">&#x27;html.parser&#x27;</span>)<br>    <span class="hljs-comment"># 创建文件夹</span><br>    createFile(save_path)<br>    <span class="hljs-comment"># 获取首页总页数</span><br>    img_max = soup.find(<span class="hljs-string">&#x27;div&#x27;</span>, class_=<span class="hljs-string">&#x27;nav-links&#x27;</span>).find_all(<span class="hljs-string">&#x27;a&#x27;</span>)[<span class="hljs-number">3</span>].text<br>    <span class="hljs-comment"># print(&quot;总页数:&quot;+img_max)</span><br>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-built_in">int</span>(img_max) + <span class="hljs-number">1</span>):<br>        <span class="hljs-comment"># 获取每页的URL地址</span><br>        <span class="hljs-keyword">if</span> i == <span class="hljs-number">1</span>:<br>            page = mziTu<br>        <span class="hljs-keyword">else</span>:<br>            page = mziTu + <span class="hljs-string">&#x27;page/&#x27;</span> + <span class="hljs-built_in">str</span>(i)<br>        file = save_path + <span class="hljs-string">&#x27;/&#x27;</span> + <span class="hljs-built_in">str</span>(i)<br>        createFile(file)<br>        <span class="hljs-comment"># 下载每页的图片</span><br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;套图页码：&quot;</span> + page)<br>        download(page, file)<br><br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    main()<br></code></pre></div></td></tr></table></figure>

<h2 id="四：-参考文献"><a href="#四：-参考文献" class="headerlink" title="四： 参考文献"></a>四： 参考文献</h2><p><a target="_blank" rel="noopener" href="https://gitee.com/52itstyle/Python">小柒2012 / 从零学Python / Day01</a></p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/python/">python</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/python/">python</a>
                    
                      <a class="hover-with-bg" href="/tags/%E7%88%AC%E5%9B%BE/">爬图</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/02/16/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Python/you-get%E4%B8%8B%E8%BD%BD%E8%A7%86%E9%A2%91/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">you-get下载视频</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/02/15/hexo/hexo%E4%B8%80%E9%94%AE%E4%B8%8A%E4%BC%A0%E9%83%A8%E7%BD%B2%E8%84%9A%E6%9C%AC%E7%9A%84%E6%9E%84%E5%BB%BA/">
                        <span class="hidden-mobile">hexo一键上传部署脚本的构建</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js', function () {
        new Valine({
          el: "#valine",
          app_id: "YzLqNtMw1YEwwACli1FUsIUM-gzGzoHsz",
          app_key: "HLUt5izfTvTcbEbOrA59W92a",
          placeholder: "畅所欲言...",
          path: window.location.pathname,
          avatar: "robohash",
          meta: ["nick","mail","link"],
          pageSize: "10",
          lang: "zh-CN",
          highlight: true,
          recordIP: false,
          serverURLs: "",
        });
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->

  <div class="col-lg-7 mx-auto nopadding-x-md">
    <div class="container custom post-custom mx-auto">
      <img src="https://closer_laps.coding.net/p/picture/d/picture/git/raw/master/pay/pay.png" srcset="/img/loading.gif" lazyload class="rounded mx-auto d-block mt-3" style="width:355.4px; height:200px;">
    </div>
  </div>


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- LeanCloud 统计PV -->
        <span id="leancloud-site-pv-container" style="display: none">
            总访问量 
            <span id="leancloud-site-pv"></span>
             次
          </span>
      
      
        <!-- LeanCloud 统计UV -->
        <span id="leancloud-site-uv-container" style="display: none">
            总访客数 
            <span id="leancloud-site-uv"></span>
             人
          </span>
      

    
  </div>


  
  <!-- 备案信息 -->
  <div class="beian">
    <span>
      <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
        苏ICP备20032307号
      </a>
    </span>
    
      
        <span>
          <a
            href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=32020602001023"
            rel="nofollow noopener"
            class="beian-police"
            target="_blank"
          >
            
              <span style="visibility: hidden; width: 0">|</span>
              <img src="/img/police_beian.png" srcset="/img/loading.gif" lazyload alt="police-icon"/>
            
            <span>苏公网安备 32020602001023号</span>
          </a>
        </span>
      
    
  </div>


  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.2/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.0/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js" ></script>




  <script defer src="/js/leancloud.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    (function () {
      var path = "/local-search.xml";
      $('#local-search-input').on('click', function() {
        searchFunc(path, 'local-search-input', 'local-search-result');
      });
      $('#modalSearch').on('shown.bs.modal', function() {
        $('#local-search-input').focus();
      });
    })()
  </script>





  

  
    <!-- MathJax -->
    <script>
      MathJax = {
        tex: {
          inlineMath: [['$', '$'], ['\\(', '\\)']]
        },
        options: {
          renderActions: {
            findScript: [10, doc => {
              document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
                const display = !!node.type.match(/; *mode=display/);
                const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
                const text = document.createTextNode('');
                node.parentNode.replaceChild(text, node);
                math.start = { node: text, delim: '', n: 0 };
                math.end = { node: text, delim: '', n: 0 };
                doc.math.push(math);
              });
            }, '', false],
            insertedScript: [200, () => {
              document.querySelectorAll('mjx-container').forEach(node => {
                let target = node.parentNode;
                if (target.nodeName.toLowerCase() === 'li') {
                  target.parentNode.classList.add('has-jax');
                }
              });
            }, '', false]
          }
        }
      };
    </script>

    <script async src="https://cdn.jsdelivr.net/npm/mathjax@3.1.2/es5/tex-svg.js" ></script>

  








  
    <!-- Baidu Analytics -->
    <script defer>
      var _hmt = _hmt || [];
      (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?608f2baddd361128381ad2bf9377bf89";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
  

  

  

  

  

  





<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
